package com.kobe.game_60;

import com.kobe.util.MathUtil;

/**
 * 
 * The first two consecutive numbers to have two distinct prime factors are:
 * 
 * 14 = 2 × 7 15 = 3 × 5
 * 
 * The first three consecutive numbers to have three distinct prime factors are:
 * 
 * 644 = 2² × 7 × 23 645 = 3 × 5 × 43 646 = 2 × 17 × 19.
 * 
 * Find the first four consecutive integers to have four distinct primes
 * factors. What is the first of these numbers?
 * 
 * 
 */
public class _47 {

    public static int getDistinctPrimeCount(int[] factors) {
        int factor = 0;
        int factorCount = 0;
        for (int temp : factors) {
            if (factor == temp) {
                continue;
            } else {
                factor = temp;
                factorCount++;
            }
        }
        return factorCount;
    }

    public static void main(String[] args) {
        int first = 0;
        int bound = 4;
        long begin = System.currentTimeMillis();
        for (int i = 2;;) {
            first = getDistinctPrimeCount(MathUtil.getFactors(i++));
            if (first == bound) {
                if (getDistinctPrimeCount(MathUtil.getFactors(i++)) == bound) {
                    if (getDistinctPrimeCount(MathUtil.getFactors(i++)) == bound) {
                        if (getDistinctPrimeCount(MathUtil.getFactors(i++)) == bound) {
                            System.out.println(i - bound);
                            break;
                        }
                    }
                }
            } 
        }
        long end = System.currentTimeMillis();
        System.out.println(end - begin);
    }
}
